home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / music and sound / qtimadecompression / headers / wave.h < prev   
Encoding:
C/C++ Source or Header  |  2000-06-23  |  6.0 KB  |  228 lines

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Header information needed to parse Microsoft's WAVE formatted sounds.
  5. **
  6. **    by Mark Cookson, Apple Developer Technical Support
  7. **
  8. **    File:    WAVE.h
  9. **
  10. **    Copyright ©1996 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "Apple Sample
  17. **    Code" after having made changes. If you're going to re-distribute the
  18. **    source, we require that you make it clear in the source that the code
  19. **    was descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. /* This was made from reading a document called wave.pdf which is an excerpt from
  23.    RIFFMCI.RTF, "Multimedia Programming Interface and Data Specification v1.0".
  24.  
  25.    This code does what I need, and worked with the WAVE files I had handy.
  26.    It may not work in all cases.
  27. */
  28.  
  29. #ifndef __WAVE__
  30. #define __WAVE__
  31.  
  32. #include <Errors.h>
  33. #include <Files.h>
  34. #include <Sound.h>
  35. #include <Types.h>
  36.  
  37. #ifndef __SOUNDSTRUCT__
  38. #include "SoundStruct.h"
  39. #endif
  40.  
  41. #ifndef __DBFFERRORS__
  42. #include "DBFF_Errors.h"
  43. #endif
  44.  
  45. #ifndef __SETUPDBHEADER__
  46. #include "SetupDBHeader.h"
  47. #endif
  48.  
  49. #ifndef __DEFINES__
  50. #include "Defines.h"
  51. #endif
  52.  
  53. #define kWAVEFORMID                (1<<0)
  54. #define kWAVEID                    (1<<1)
  55. #define kFormatID                (1<<2)
  56. #define kWAVEListID                (1<<3)
  57. #define kSilenceID                (1<<4)
  58. #define kCueID                    (1<<5)
  59. #define kFactID                    (1<<6)
  60. #define kPlaylistID                (1<<7)
  61. #define kAssocDataID            (1<<8)
  62. #define kLabelID                (1<<9)
  63. #define kNoteID                    (1<<10)
  64. #define kTextWithLenID            (1<<12)
  65. #define kEmbededFileID            (1<<13)
  66. #define kWAVEDataID                (1<<14)
  67.  
  68. enum {
  69.     WAVEFORMID                    = 'RIFF',
  70.     WAVEID                        = 'WAVE',
  71.     FormatID                    = 'fmt ',
  72.     WAVEListID                    = 'wavl',
  73.     SilenceID                    = 'slnt',
  74.     CueID                        = 'cue ',
  75.     FactID                        = 'fact',
  76.     PlaylistID                    = 'plst',
  77.     AssocDataID                    = 'adtl',
  78.     LabelID                        = 'labl',
  79.     NoteID                        = 'note',
  80.     TextWithLenID                = 'ltxt',
  81.     EmbededFileID                = 'file',
  82.     WAVEDataID                    = 'data'
  83. };
  84.  
  85. #define WAVE_FORMAT_PCM        (0x0001)        /* Microsoft Pulse Code Modulation (PCM) format */
  86. #define WAVE_FORMAT_ADPCM    (0x0002)        /* A WAVE Adaptive Differential Pulse Code Modulation file I saw once */
  87. #define WAVE_FORMAT_MULAW    (0x0007)        /* A WAVE mu-law file that I saw once */
  88. #define WAVE_FORMAT_IMA        (0x0011)        /* A WAVE IMA4 file that I saw once */
  89. #define IBM_FORMAT_MULAW    (0x0101)        /* IBM mu-law format */
  90. #define IBM_FORMAT_ALAW        (0x0102)        /* IBM a-law format */
  91. #define IBM_FORMAT_ADPCM    (0x0103)        /* IBM AVC Adaptive Differential Pulse Code Modulation format */
  92. #define kWAVEChunkBufferSize    128
  93.  
  94. // typedef unsigned long ID;
  95.  
  96. #pragma options align=mac68k
  97. typedef struct WAVEChunkHeader {
  98.     ID                    ckID;
  99.     long                fileSize;
  100. }WAVEChunkHeader;
  101.  
  102. typedef struct WAVEContainerChunk {
  103.     ID                    ckID;
  104.     long                ckSize;
  105.     ID                    formType;
  106. }WAVEContainerChunk;
  107.  
  108. typedef struct fmtChunk {
  109.     ID                    ckID;
  110.     long                ckSize;
  111.     short                wFormatTag;            /* Number indicating WAVE format category */
  112.     short                wChannels;            /* Number of channels 1 for mono 2 for stereo */
  113.     long                dwSamplesPerSec;    /* Sampling rate in samples per second */
  114.     long                dwAvgBytesPerSec;    /* Average number of bytes per second (could be used to estimate buffer sizes) */
  115.     short                wBlockAlign;        /* Block alignment in bytes of the waveform data, always process an integer multiple of this number */
  116. }fmtChunk;
  117.  
  118. typedef struct PCMFmtSpecChunk {
  119.     ID                    ckID;
  120.     long                ckSize;
  121.     short                wBitsPerSample;        /* Sample size */
  122. }PCMFmtSpecChunk;
  123.  
  124. typedef struct factChunk {
  125.     ID                    ckID;
  126.     long                ckSize;
  127.     long                dwFileSize;            /* Number of samples */
  128. }factChunk;
  129.  
  130. typedef struct cuePointsChunk {
  131.     ID                    ckID;
  132.     long                ckSize;
  133.     long                dwCuePoints;        /* Count of cue points */
  134.     /* There may be multiple number of these */
  135.     long                dwName;
  136.     long                dwPosition;
  137.     long                fccChunk;
  138.     long                dwChunkStart;
  139.     long                dwBlockStart;
  140.     long                dwSampleOffset;
  141. }cuePointsChunk;
  142.  
  143. typedef struct playlistChunk {
  144.     ID                    ckID;
  145.     long                ckSize;
  146.     long                dwSegments;            /* Count of play segments */
  147.     /* There may be multiple number of these */
  148.     long                dwName;
  149.     long                dwLength;
  150.     long                dwLoops;
  151. }playlistChunk;
  152.  
  153. //typedef struct waveDataChunk {
  154. //    ID                    ckID;
  155. //    short                something;            /* I don't know what this is */
  156. //}waveDataChunk;
  157.  
  158. typedef struct labelChunk {
  159.     ID                    ckID;
  160.     long                ckSize;
  161.     long                dwName;
  162.     char                data[1];            /* This is a null terminated string */
  163. }labelChunk;
  164.  
  165. typedef struct noteChunk {
  166.     ID                    ckID;
  167.     long                ckSize;
  168.     long                dwName;
  169.     char                data[1];            /* This is a null terminated string */
  170. }noteChunk;
  171.  
  172. typedef struct ltxtChunk {
  173.     ID                    ckID;
  174.     long                ckSize;
  175.     long                dwName;
  176.     long                dwSampleLength;
  177.     long                dwPurpose;
  178.     short                wCountry;
  179.     short                wLanguage;
  180.     short                wDialect;
  181.     short                wCodePage;
  182.     char                data[1];            /* This is a null terminated string */
  183. }ltxtChunk;
  184.  
  185. typedef struct fileChunk {
  186.     ID                    ckID;
  187.     long                ckSize;
  188.     long                dwName;
  189.     long                dwMedType;
  190.     char                data[1];            /* This is a null terminated string */
  191. }fileChunk;
  192.  
  193. typedef struct assocDataListChunk {
  194.     ID                    ckID;
  195.     long                ckSize;
  196.     labelChunk            labelInfo;
  197.     noteChunk            noteInfo;
  198.     ltxtChunk            ltxtInfo;
  199.     fileChunk            fileInfo;
  200. }assocDataListChunk;
  201.  
  202. typedef union {
  203.     WAVEChunkHeader            generic;
  204.     WAVEContainerChunk        container;
  205.     fmtChunk                fmt;
  206.     factChunk                fact;
  207.     cuePointsChunk            cuePoints;
  208.     playlistChunk            playList;
  209.     assocDataListChunk        assocData;
  210. //    waveDataChunk            waveData;
  211.     PCMFmtSpecChunk            waveData;
  212.     fileChunk                file;
  213.     ltxtChunk                ltxt;
  214.     noteChunk                note;
  215.     labelChunk                label;
  216. }WAVETemplate, *WAVETemplatePtr;
  217. #pragma options align=reset
  218.  
  219. OSErr    ASoundGetWAVEHeader        (SoundInfoPtr theSoundInfo, long *len, fmtChunk *formatChunk);
  220.  
  221. short        SwapShort                (const short theShort);
  222. long        SwapLong                (const long theLong);
  223. long        ReverseLong                (const long theLong);
  224.  
  225. #define stillMoreDataWAVEToRead        ((chunkFlags & kWAVEFORMID) && (!(chunkFlags & kFormatID) || !(chunkFlags & kWAVEDataID)) && (err == noErr))
  226.  
  227. #endif
  228.